from django.core.management.base import BaseCommand
from apps.oaauth.models import OADepartment,OAAbstractUser
# 运行命令如：python manage.py inituser

class Command(BaseCommand):
    def handle(self, *args, **options):
        dongdong = OAAbstractUser.objects.create_superuser(
            email="dongdong@qq.com",
            realname="东东",
            password="123456",
            department=OADepartment.objects.get(name="董事会"),
        )
        duoduo = OAAbstractUser.objects.create_superuser(
            email="duoduo@qq.com",
            realname="多多",
            password="123456",
            department=OADepartment.objects.get(name="董事会"),
        )
        zhangsan = OAAbstractUser.objects.create_user(
            email="zhangsan@qq.com",
            realname="张三",
            password="123456",
            department=OADepartment.objects.get(name="产品开发部"),
        )
        lisi = OAAbstractUser.objects.create_user(
            email="lisi@qq.com",
            realname="李四",
            password="123456",
            department=OADepartment.objects.get(name="运营部"),
        )
        wangwu = OAAbstractUser.objects.create_user(
            email="wangwu@qq.com",
            realname="王五",
            password="123456",
            department=OADepartment.objects.get(name="人事部"),
        )
        zhaoliu = OAAbstractUser.objects.create_user(
            email="zhaoliu@qq.com",
            realname="赵六",
            password="123456",
            department=OADepartment.objects.get(name="财务部"),
        )
        sunqi = OAAbstractUser.objects.create_user(
            email="sunqi@qq.com",
            realname="孙七",
            password="123456",
            department=OADepartment.objects.get(name="销售部"),
        )
        #给部门指定leader和manage
        OADepartment.objects.filter(name="董事会").update(leader=dongdong,manage=None)
        OADepartment.objects.filter(name="产品开发部").update(leader=zhangsan,manage=dongdong)
        OADepartment.objects.filter(name="运营部").update(leader=lisi,manage=dongdong)
        OADepartment.objects.filter(name="人事部").update(leader=wangwu,manage=duoduo)
        OADepartment.objects.filter(name="财务部").update(leader=zhaoliu,manage=duoduo)
        OADepartment.objects.filter(name="销售部").update(leader=sunqi,manage=dongdong)
        self.stdout.write(self.style.SUCCESS('用户数据初始化成功！'))